package com.llb666.shop.user.api.controller;

import com.llb666.shop.user.api.vo.auth.Account;
import com.llb666.shop.user.api.vo.auth.AuthResponse;
import com.llb666.shop.user.application.AuthApplication;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户权限相关接口.
 *
 * @author llb666
 */
@RestController
@Tag(name = "用户权限相关接口")
@RequestMapping("/auth")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class UserAuthController {

    private final AuthApplication application;

    @Operation(summary = "生成token")
    @GetMapping("/token")
    public AuthResponse token(@Parameter(description = "用户Id") @RequestParam("userId") String userId) {
        return application.token(userId);
    }

    @Operation(summary = "验证token,验证是否已经登录")
    @PostMapping("/verify")
    public AuthResponse verify(@RequestBody Account account) {
        return application.verify(account);
    }

    @Operation(summary = "刷新token,重新获取登录密钥")
    @PostMapping("/refresh")
    public AuthResponse refresh(@Parameter(description = "refreshToken") @RequestParam("refreshToken") String refreshToken) {
        return application.refresh(refreshToken);
    }

    @Operation(summary = "删除token,退出登录")
    @DeleteMapping("delete")
    public AuthResponse delete(@RequestBody Account account) {
        return application.delete(account);
    }

}
